import {
    Entity,
    PrimaryGeneratedColumn,
    Column,
    getRepository,
    createConnection,
    Connection,
    ConnectionOptions
} from 'typeorm';
import { GameConfig } from './game_config';

const connectionConfig: ConnectionOptions = process.env.NODE_ENV === 'production' ?
    {
        type: 'mysql',
        host: '10.5.38.44',
        port: 3806,
        username: 'root',
        password: 'Mingyuanyun!test',
        database: 'hr_activity',
        entities: [
            GameConfig
        ]
    } :
    {
        type: 'mysql',
        host: '10.5.10.133',
        port: 3306,
        username: 'root',
        password: '',
        database: 'hr_activity',
        entities: [
            GameConfig
        ]
    };

export class MyConnection {

    static myConnection: Connection;

    static async getInstance() {
        if (MyConnection.myConnection === undefined) {
            MyConnection.myConnection = await createConnection(connectionConfig);
        }

        return MyConnection.myConnection;
    }
}
